package com.area.controller;

import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.area.util.ExportWordUtil;

@RestController
@RequestMapping("/export")
@CrossOrigin
public class ExportDocController {
    @RequestMapping(value = "/exportWord", method = RequestMethod.GET)
    public void exportWord(HttpServletRequest request, HttpServletResponse response) throws Exception {
        String fileName = "测试.doc"; // 文件名称
        Map<String, Object> dataMap = new HashMap<>();
        dataMap.put("title", "freemarker导出word"); // 设置要导出的数据,这里的title要和word模板中保持一致
        dataMap.put("name", "关峰");
        dataMap.put("age", "18");
        dataMap.put("sex", "男");
        new ExportWordUtil("UTF-8").exportDoc(response, fileName, "test.", dataMap);
    }
}

